<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8" />
    <meta name="referrer" content="no-referrer" />
    <meta
      name="viewport"
      content="width=device-width,initial-scale=1.0,maximum-scale=1.0,minimum-scale=1,user-scalable=no"
    />
    <meta name="format-detection" content="telephone=no, email=no" />
    <title>Derucci SDK</title>
    <script src="https://cdn.bootcss.com/vConsole/3.3.4/vconsole.min.js"></script>
    <script>
      function onNetworkChanged() {}
      function onResume() {}
      function onPause() {}
      new VConsole();
    </script>
    <style>
      button {
        margin: 10px;
        padding: 10px;
        width: 80vw;
      }
    </style>
  </head>
  <body>
    <div style="display: flex;justify-content: center;align-items: center;height: 100vh;flex-direction: column;">
        <!-- <button onclick="apiTest()">按钮</button> -->
        <button onclick="connectToMqtt()">连接Mqtt</button>
        <button onclick="getMqttConnectConfig()">MQTT-获取联网信息</button>
        <button onclick="getMqttSubTopics()">MQTT-获取订阅主题</button>
        <button onclick="dayReportPreForceGenerate()">日报告-手动生成报告</button>
        <button onclick="getDaySleepById()">日报告-通过报告ID获取报告详情</button>
        <button onclick="getDaySleep()">日报告-获取指定日期设备最新报告</button>
        <button onclick="getDaySleepCalendar()">日报告-获取设备日历统计数据</button>
        <button onclick="getWeekMonthSleepById()">周月报告-通过报告ID获取报告详情</button>
        <button onclick="getWeekMonthSleep()">周月报告-获取指定日期设备最新报告</button>
        <button onclick="getWeekMonthSleepCalendar()">周月报告-获取设备日历统计数据</button>
    </div>
    <script>
      let deivceId = "B0818425F0AC";
      let periodType = "week";
      let reqVersion = "V2";
      let docDate = undefined
      // let docDate = "2024/01/02";
      setTimeout(() => {
        derucci.setDebugMode(true);
        derucci.setEnv("dev");
        // Mqtt数据监听
        console.log(derucci.adjustMatch({
          gender: "male",
          age: 50,
          height: 70,
          weight: 65
        }));
        window.callback = (data) => {
          console.log(`监听数据：`, data); 
        };
        derucci.addMqttEventListener("*", window.callback);
      }, 1000)
      async function apiTest()  {
        try {
          console.log("开始请求");
          const res = await derucci.apiTest();
          console.log("请求结束");
        } catch(e) {
          console.log("捕获到错误", e);
        }
      }

      async function connectToMqtt()  {
        try {
          console.log("开始请求");
          const res = await derucci.connectToMqtt(deivceId);
          console.log("请求结束");
        } catch(e) {
          console.log("捕获到错误", e);
        }
      }

      async function getMqttConnectConfig()  {
        try {
          console.log("开始请求");
          const res = await derucci.getMqttConnectConfig();
          console.log("请求结束");
        } catch(e) {
          console.log("捕获到错误", e);
        }
      }

      async function getMqttSubTopics()  {
        try {
          console.log("开始请求");
          const res = await derucci.getMqttSubTopics(deivceId);
          console.log("请求结束");
        } catch(e) {
          console.log("捕获到错误", e);
        }
      }

      async function dayReportPreForceGenerate() {
        try {
          console.log("开始请求");
          const res = await derucci.dayReportPreForceGenerate({
            machineCode: "C049EFCAD2A4",
            machineUniqueCode: "C049EFCAD2A4####left"
          });
          console.log("请求结束");
        } catch(e) {
          console.log("捕获到错误", e);
        }
      }

      async function getDaySleepById()  {
        try {
          console.log("开始请求");
          const res = await derucci.getDaySleepById({
              docId: "64e4276c5c17000007f82218",
              machineUniqueCode: "C049EFCAD2A4####left"
          });
          console.log("请求结束");
        } catch(e) {
          console.log("捕获到错误", e);
        }
      }


      async function getDaySleep()  {
        try {
          console.log("开始请求");
          const res = await derucci.getDaySleep({
            docDate: "2024/04/02",
            machineUniqueCode: "C049EFCAD2A4####right",
          });
          console.log("请求结束");
        } catch(e) {
          console.log("捕获到错误", e);
        }
      }

      async function getDaySleepCalendar()  {
        try {
          console.log("开始请求");
          const res = await derucci.getDaySleepCalendar({
            docDate: "2024/04/02",
            machineUniqueCode: "C049EFCAD2A4####right",
          });
          console.log("请求结束");
        } catch(e) {
          console.log("捕获到错误", e);
        }
      }

      async function getWeekMonthSleepById()  {
        try {
          console.log("开始请求");
          const res = await derucci.getWeekMonthSleepById({
            docId: "67bd5d8543b0b82d64a8cfdd",
            machineUniqueCode: "58CF7902FE2E####left"
          });
          console.log("请求结束");
        } catch(e) {
          console.log("捕获到错误", e);
        }
      }

      async function getWeekMonthSleep()  {
        try {
          console.log("开始请求");
          const res = await derucci.getWeekMonthSleep({
            periodType: "week", // week、month
            docDate: docDate, // ""
            machineUniqueCode: "B0818425F0AC####left",
          });
          console.log("请求结束");
        } catch(e) {
          console.log("捕获到错误", e);
        }
      }

      async function getWeekMonthSleepCalendar()  {
        try {
          console.log("开始请求");
          const res = await derucci.getWeekMonthSleepCalendar({
            periodType: periodType, // week、month
            docDate: "2025/02/01",
            machineUniqueCode: "58CF7902FE2E####left",
          });
          console.log("请求结束");
        } catch(e) {
          console.log("捕获到错误", e);
        }
      }

      
    </script>
  </body>
</html>
